exports.install = function (Vue, options) {

  /**
   * 检查返回结果
   */
  Vue.prototype.checkResponse = function(res) {
    if (res.status !== 200) {
      this.$message.error("请求结果状态码错误：" + res.status);
      return false;
    }

    let result = res.body;
    if (result.code !== 0) {
      this.$message.error("请求结果异常：" + result.msg);
      return false;
    }

    return true;
  };

  /**
   * 请求出现异常，打印异常信息
   */
  Vue.prototype.messageException = function(e) {
    this.$message.error("请求异常: " + e);
    // this.$message.error("请求异常: " + e.bodyText);
  };

  /**
   * http客户端
   */
  Vue.prototype.httpGet = function(url, callback) {
    return this.httpGet2(url, {}, callback);
  };
  Vue.prototype.httpGet2 = function(url, param, callback) {
    this.$http.get(url, param, {emulateJSON: true}).then((res) => {
      if (!this.checkResponse(res)) {
        return null;
      }

      callback(res.body.data);
    }).catch((e) => { this.messageException(e); });
  };
  Vue.prototype.httpPost = function(url, param, callback) {
    this.$http.post(url, param, {emulateJSON: true}).then((res) => {
      if (!this.checkResponse(res)) {
        return null;
      }

      console.info("aaaa");
      console.info(res.body.data);
      callback(res.body.data);
    }).catch((e) => { this.messageException(e); });
  };
  Vue.prototype.httpPut = function(url, param, callback) {
    this.$http.put(url, param, {emulateJSON: true}).then((res) => {
      if (!this.checkResponse(res)) {
        return null;
      }

      callback(res.body.data);
    }).catch((e) => { this.messageException(e); });
  };
  Vue.prototype.httpDelete = function(url, param, callback) {
    this.$http.delete(url, param, {emulateJSON: true}).then((res) => {
      if (!this.checkResponse(res)) {
        return null;
      }

      callback(res.body.data);
    }).catch((e) => { this.messageException(e); });
  };
};
